#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int maxProfit(vector<int>& prices) 
{
    int buy=INT_MAX;
    int profit=0;
    for (int i = 0; i < prices.size(); i++)
    {
        buy=min(buy,prices[i]);
        profit=max(profit,prices[i]-buy);
    }
    return profit;
}

int main()
{
    vector<int> prices{7,1,5,3,6,4};
    cout << maxProfit(prices)<<flush;
    return 0;
}